package com.example.Sao.MyFragment;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.CardView;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;

import com.example.Sao.R;

/**
 * @ProjectName: scan
 * @Package: com.example.MyApplication.MyFragment
 * @ClassName: RoomChooseFragment
 * @Description: java类作用描述
 * @Author: 作者名
 * @CreateDate: 2020/2/24 12:57
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/2/24 12:57
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class RoomChooseFragment extends DialogFragment implements View.OnClickListener {
  private AppCompatTextView iv_buliding,iv_floor,iv_room;
  private DataBcakListener dataBcakListener;
  private CardView iv_sure;
  private AppCompatImageView iv_back;
  private Context mContext;
  private RelativeLayout room,floor,buliding;
  @NonNull
  @Override
  public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    return super.onCreateDialog(savedInstanceState);
  }

  public void setDataBcakListener(DataBcakListener dataBcakListener) {
    this.dataBcakListener = dataBcakListener;
  }

  public void setmContext(Context mContext) {
    this.mContext = mContext;
  }

  @Override
  public void onClick(View v) {
    switch (v.getId()){
      case R.id.iv_back:
        RoomChooseFragment.this.dismiss();
        break;
      case R.id.iv_sure:
        if (dataBcakListener!=null){
          dataBcakListener.DataBcakListener("ADSAd");
        }
        RoomChooseFragment.this.dismiss();
        break;
      default:
        break;
    }
  }

  @Nullable
  @Override
  public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    Window window = this.getDialog().getWindow();
    //去掉dialog默认的padding
    DisplayMetrics dm = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
    window.getDecorView().setPadding(0, 0, 0, 0);
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.width = (int) (dm.widthPixels * 0.75);
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    //设置dialog的位置在中间
    lp.gravity = Gravity.CENTER;
    //设置dialog的动画
    lp.windowAnimations = R.style.dialogAnim;
    window.setAttributes(lp);
    window.setBackgroundDrawable(new ColorDrawable());
    View view = inflater.inflate(R.layout.fragment_room_choose,container,false);
    return view;
  }

  @Override
  public void onViewCreated(View view,  Bundle savedInstanceState) {
    iv_buliding = view.findViewById(R.id.iv_buliding);
    iv_floor = view.findViewById(R.id.iv_floor);
    iv_room = view.findViewById(R.id.iv_room);
    iv_sure = view.findViewById(R.id.iv_sure);
    iv_back = view.findViewById(R.id.iv_back);
    buliding = view.findViewById(R.id.iv_choose_buliding);
    room = view.findViewById(R.id.iv_room_choose);
    floor = view.findViewById(R.id.iv_floor_choose);
    iv_sure.setOnClickListener(this);
    floor.setOnClickListener(this);
    room.setOnClickListener(this);
    buliding.setOnClickListener(this);
    iv_back.setOnClickListener(this);
    if(getArguments()!=null){
      Bundle bundle = getArguments();
      iv_buliding.setText(bundle.getString("buliding"));
      iv_floor.setText(bundle.getString("floor"));
      iv_room.setText(bundle.getString("room"));
    }
    super.onViewCreated(view, savedInstanceState);
  }

  @Override
  public void onStart() {
    super.onStart();
  }

  @Override
  public void onDestroy() {
    super.onDestroy();
  }

  public interface DataBcakListener{
    public void DataBcakListener(String data);
  }
}
